package cn.buk.tms.eotms.controller;

import cn.buk.common.dto.CommonDto;
import cn.buk.tms.eotms.dto.TrainOrderDto;
import cn.buk.tms.eotms.sc.TrainOrderSearchCriteria;
import cn.buk.tms.eotms.service.TrainOrderService;
import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yfdai
 */
@RestController
@RequestMapping("/train")
public class TrainOrderController extends BaseController {

  @Autowired
  private TrainOrderService trainOrderService;

  /**
   * 搜索酒店订单
   * @param request
   * @param sc
   * @return
   */
  @RequestMapping("/orders")
  public CommonDto<TrainOrderDto> searchTrainOrders(HttpServletRequest request,
      @ModelAttribute("sc") TrainOrderSearchCriteria sc) {
    List<TrainOrderDto> datas = trainOrderService.searchTrainOrders(getUserId(request), sc);

    CommonDto<TrainOrderDto> commonDto = new CommonDto<>();
    commonDto.setDataList(datas);
    commonDto.setPage(sc.getPage());

    return commonDto;
  }

  /**
   * 获取火车票订单详情
   * @param request
   * @return
   */
  @RequestMapping("/order/{orderId}")
  public TrainOrderDto searchTrainOrders(HttpServletRequest request,
      @PathVariable("orderId") final int orderId) {
    return trainOrderService.getTrainOrderById(getUserId(request), orderId);
  }
}
